import Vue from 'vue'
import store from './store'
import router from './router'
import _ from 'lodash'

import './plugins'
import './common/style/normalize.css'
import './common/style/common.less'

Vue.config.productionTip = false;
window.store = store;

new Vue({
  store,
  router,
  render: h => h('router-view'),
  mounted() {
    this.update();
    window.addEventListener("resize", this.update);
  },
  destroyed() {
    window.removeEventListener("resize", this.update);
  },
  methods: {
    onUpdate() {
      _.debounce(this.update, 500)
    },
    update() {
      let w = 0;
      let h = 0;

      if (window.innerWidth) {
        w = window.innerWidth;
      } else if (document.body && document.body.clientWidth) {
        w = document.body.clientWidth;
      }

      if (window.innerHeight) {
        h = window.innerHeight;
      } else if (document.body && document.body.clientHeight) {
        h = document.body.clientHeight;
      }

      // 通过深入 Document 内部对 body 进行检测，获取窗口大小
      if (document.documentElement) {
        if (document.documentElement.clientWidth) {
          w = document.documentElement.clientWidth;
        }
        if (document.documentElement.clientHeight) {
          h = document.documentElement.clientHeight;
        }
      }

      this.$store.commit('wSize/UPDATE_WINDOW_SIZE', {width: w, height: h})
    }
  }
}).$mount('#app');
